/**
 * Created with IntelliJ IDEA.
 * Description: 压缩字符串（一）
 * User: wangxin
 * Date: 2024-08-05
 * Time: 20:18
 */
public class test4 {
    public class Solution {
        public String compressString (String param) {
            // write code here
            StringBuilder res = new StringBuilder();
            if(param.length()<=1)return param;
            int count  = 1;
            for(int i=1;i<param.length();++i){
                if(param.charAt(i)==param.charAt(i-1)){
                    count++;
                }
                else {
                    if(count==1){
                        res.append(param.charAt(i-1));
                    }
                    else {
                        res.append(param.charAt(i-1)+""+count);
                        count=1;
                    }
                }
            }
            if(count==1) res.append(param.charAt(param.length()-1));
            else res.append(param.charAt(param.length()-1)+""+count);
            return res.toString();
        }
    }

}
